package cn.itcast.work.service.system_service;

//import cn.itcast.work.dao.system.SystemDaoImpl;

import cn.itcast.work.dao.system.SystemMapper;
//import cn.itcast.work.dao.system.TextDaoImpl;
import cn.itcast.work.dao.system.TextMapper;
import cn.itcast.work.pojo.TextWhole;
import cn.itcast.work.pojo.Text_show;
import cn.itcast.work.pojo.User;
import cn.itcast.work.pojo.User_show;
import com.github.pagehelper.Page;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("systemService")
@Slf4j
public class SystemService {

//    @Resource(name = "textDao")
//    private TextDaoImpl textDao;
//
//    @Resource(name = "systemDao")
//    private SystemDaoImpl systemDao;

    @Autowired
    private SystemMapper systemMapper;

    @Autowired
    private TextMapper textMapper;

    //首页搜索博客 动态查询博客
    public List<Map<String, Object>> toSearchText(String key, int page, int pageSize) {
//        System.out.println("key = " + key);
//        System.out.println("搜索文章 service");
        log.info("service--搜索文章 {}", key);
        List<Map<String, Object>> textWholeList = textMapper.selectText(key, page, pageSize);
        textWholeList.forEach(text -> System.out.println(text));
        return textWholeList;

    }

    //查询所有博客
    public List<TextWhole> toselectAllText() {
        System.out.println("后台显示所有文章 service");
        return systemMapper.selectAll();
    }

    //插入数据
    public boolean toInsert(String phone, String title) {
        System.out.println("插入首页表 service");
        int i = systemMapper.insertText(phone, title);
        return i > 0;

    }

    //删除博客
    public boolean toDelete(String phone, String title) {
        System.out.println("管理员删除表 service");
        //先在 首页表 home_page 撤回
        systemMapper.cancelText(title);
        //再删除 text 中的表
        int i = systemMapper.deleteText(phone, title);

        return i > 0;
//        return systemDao.insertText(phone, title);
    }

    //撤回博客
    public boolean toCancel(String title) {
        System.out.println("撤下首页表 service");
        int i = systemMapper.cancelText(title);

        return i > 0;
//        return systemDao.insertText(phone, title);
    }


    //显示推送博客
    public List<Text_show> selectPutText() {
//        System.out.println("查询推送表 service");
        return systemMapper.selectPutText();
    }

    //显示所有用户
    public List<User> selectAllUser() {
        System.out.println("查询所有用户 service");
        return systemMapper.selectAllUser();
    }

    //插入推送用户
    public boolean toInsertUser(String phone, String name) {
        System.out.println("插入推送用户 service");
        int i = systemMapper.insertUser(phone, name);
        return i > 0;

    }

    //撤销用户
    public boolean toCancelUser(String name) {
        System.out.println("撤销用户 service");
        int i = systemMapper.cancelUser(name);
        return i > 0;
//        return systemDao.insertText(phone, title);
    }

    public List<User> toSelctPutUser() {
//        System.out.println("查询用户  service");
        return systemMapper.selectPutUser();
    }

    public List<String> toSelectPutTitle() {
        System.out.println("查询推送标题  service");
        return systemMapper.selectPutTitle();
    }

}
